#define WTCON	(*(volatile unsigned long *)0x53000000)
#define MEM_CTL_BASE	0x48000000

void disable_watch_dog(void);
void memsetup(void);

void disable_watch_dog(void)
{
	WTCON = 0;
}

void memsetup(void)
{
#if 1
	unsigned long const mem_cfg_val[] = {
		0x22011110,
		0x00000700,
		0x00000700,
		0x00000700,

		0x00000700,
		0x00000700,
		0x00000700,

		0x00018005,
		0x00018005,

		0x008C07A3,
		0x000000B1,
		0x00000030,
		0x00000030,
	};

	int i = 0;
	volatile unsigned long *p = (volatile unsigned long *)MEM_CTL_BASE;

	for (; i < 13; i ++)
		p[i] = mem_cfg_val[i];
#else
	volatile unsigned long *p = (volatile unsigned long *)MEM_CTL_BASE;

	/* 这个函数之所以这样赋值，而不是像前面的实验(比如mmu实验)那样将配置值
	 * 写在数组中，是因为要生成”位置无关的代码”，使得这个函数可以在被复制到
	 * SDRAM之前就可以在steppingstone中运行
	 */
	/* 存储控制器13个寄存器的值 */
	p[0] = 0x22011110;     //BWSCON
	p[1] = 0x00000700;     //BANKCON0
	p[2] = 0x00000700;     //BANKCON1
	p[3] = 0x00000700;     //BANKCON2
	p[4] = 0x00000700;     //BANKCON3  
	p[5] = 0x00000700;     //BANKCON4
	p[6] = 0x00000700;     //BANKCON5
	p[7] = 0x00018005;     //BANKCON6
	p[8] = 0x00018005;     //BANKCON7

	/* REFRESH,
	 * HCLK=12MHz:  0x008C07A3,
	 * HCLK=100MHz: 0x008C04F4
	 */ 
	p[9]  = 0x008C07A3;
	p[10] = 0x000000B1;     //BANKSIZE
	p[11] = 0x00000030;     //MRSRB6
	p[12] = 0x00000030;     //MRSRB7
#endif
}
